package com.quanquan.user.controller;

import com.quanquan.user.request.TemplateIdRequest;
import com.quanquan.user.service.TemplateIdService;
import com.quanquan.user.service.weixin.MiniProgramProxy;
import enums.ResCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.response.ResultBody;

import java.util.List;

/**
 * @ClassName:TemplateIdController
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2020/4/14 14:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/template_id")
public class TemplateIdController {

    private final TemplateIdService templateIdService;

    @Autowired
    public TemplateIdController(TemplateIdService templateIdService) {
        this.templateIdService = templateIdService;
    }

    /**
     * 根据类型查找模板id
     *
     * @param request
     * @return store
     */
    @PostMapping("/find_by_type")
    public ResultBody findByType(@RequestBody TemplateIdRequest request) {
        if ( request.getType()==null) {
            return new ResultBody(ResCodeEnum.UG_PAEAMES.getCode(), ResCodeEnum.UG_PAEAMES.getMsg());
        }
        List<Object> byType = templateIdService.findByType(request);
        return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS", byType);
    }


    /**
     * 订阅消息（报名成功通知，这个在报名成功后弹出授权提醒）
     *
     * @param request
     * @return store
     */
    @PostMapping("/send_sign_up_activity_message")
    public ResultBody sendSignUpActivityMessage(@RequestBody TemplateIdRequest request) {
        boolean b = templateIdService.sendSignUpActivityMessage(request);
        if (b){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL");
    }

    /**
     * 订阅消息（注册成功）
     *
     * @param request
     * @return store
     */
    @PostMapping("/send_reg_message")
    public ResultBody sendRegMessage(@RequestBody TemplateIdRequest request) {
        boolean b = templateIdService.sendRegMessage(request);
        if (b){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL");
    }

    /**
     * 订阅消息（会员积分变动）
     *
     * @param request
     * @return store
     */
    @PostMapping("/send_integral_change_message")
    public ResultBody sendIntegralChangeMessage(@RequestBody TemplateIdRequest request) {
        boolean b = templateIdService.sendIntegralChangeMessage(request);
        if (b){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL");
    }

    /**
     * 订阅消息（停车支付）
     *
     * @param request
     * @return store
     */
    @PostMapping("/send_parking_fee_message")
    public ResultBody sendParkingFeeMessage(@RequestBody TemplateIdRequest request) {
        boolean b = templateIdService.sendParkingFeeMessage(request);
        if (b){
            return new ResultBody(ResCodeEnum.SUCCESS.getCode(), "SUCCESS");
        }
        return new ResultBody(ResCodeEnum.FAIL.getCode(), "FAIL");
    }






}
